package com.bawei.yangzongcai___day2.MVPActivity;

import com.bawei.mvp.Model.BoosModel;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * create by ertu
 * create on 2021/7/26
 * description
 */
public class FoodModel extends BoosModel implements FoodContract.foodmodel {

    @Override
    public void getdate(final Foodcallback foodcallback) {
            Okhttpcilite.getInstance().retrofit("http://www.qubaobei.com/ios/cf/")
                    //创建串的后半轴和观察者的方法
                    .create(apl.class)
                    .getdate()
                    //观察  Android的主线程
                    .observeOn(AndroidSchedulers.mainThread())
                    //订阅 调度者的计算
                    .subscribeOn(Schedulers.computation())
                    //已订阅 新的观察者的java类
                    .subscribe(new Observer<JavaMVP>() {
                        @Override
                        public void onSubscribe(Disposable d) {
                            //未订阅时
                        }

                        //下一个
                        @Override
                        public void onNext(JavaMVP javaMVP) {
                            //如果成功的话就把集合java类给接口成功
                            List<JavaMVP.DataBean> dataBeans = javaMVP.getData();
                           foodcallback.success(dataBeans);
                        }

                        @Override
                        public void onError(Throwable e) {
                            //出现错误时
                        }


                        @Override
                        public void onComplete() {
                            //完成时
                        }
                    });
    }

}
